package com.egao.appo.controller;

import com.egao.appo.entity.Message;
import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.*;
import com.egao.common.core.annotation.OperLog;
import com.egao.appo.entity.Appointments;
import com.egao.appo.service.AppointmentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;


/**
 * 用户资料
 *
 * @author : Doman
 * @version ：1.0
 * @date : 2021-07-20 09:09:53
 */

@Api(tags = "用户资料")
@RestController
@RequestMapping("/api/appo/appointments")
public class AppointmentsController extends BaseController {

    @Autowired
    private AppointmentsService appointmentsService;

    /**
     * 分页查询列表
     */
    @PreAuthorize("hasAuthority('appo:appointments:list')")
    @ApiOperation(value = "分页查询用户资料", notes = "" +
            "limit:每页显示几行 必填\n" +
            "page:第几页 必填\n" +
            " \n\n\n" +
            "返回的结果:\n" +
            "id:id\n" +
            "name:昵称\n" +
            "bCode:编号\n" +
            "pinyin:昵称拼音\n" +
            "gender:性别\n" +
            "phone:手机\n" +
            "idCardPic:身份证图片正面\n" +
            "idCardPicB:身份证图片背面\n" +
            "height:身高\n" +
            "weight:体重\n" +
            "education:学历\n" +
            "occupation:职业\n" +
            "salary:年薪\n" +
            "house:房子\n" +
            "car:车子\n" +
            "selfSituation:自身情况\n" +
            "hobby:爱好\n" +
            "requirements:择偶要求\n" +
            "birthday:生日\n" +
            "marriage:婚姻\n" +
            "nativePlace:籍贯\n" +
            "liveCity:居住\n" +
            "nativePlaceV:籍贯值\n" +
            "liveCityV:居住值\n" +
            "wechatCode:微信\n" +
            "idCard:身份证\n" +
            "educationPic:学历照片\n" +
            "photo:个人照片\n" +
            "photoPrivacy:个人照片_隐藏\n" +
            "examined: 审核状态: 未审核,未通过,已审核\n" +
            "orderNum:排序\n" +
            "createTime:创建时间\n" +
            "createUser:创建人\n" +
            "updateTime:更新时间\n" +
            "updateUser:更新人\n" +
            "", httpMethod = "GET")
    @ApiPageParam
    @GetMapping("/page")
    public JsonResult page(PageResult2<T> page, Appointments appointments) throws Exception {
        return appointmentsService.list(page, appointments, getLoginUser());
    }

    /**
     * 分页查询列表
     */
    @PreAuthorize("hasAuthority('appo:appointments:list')")
    @ApiOperation(value = "分页查询用户资料", notes = "" +
            "limit:每页显示几行 必填\n" +
            "page:第几页 必填\n" +
            " \n\n\n" +
            "返回的结果:\n" +
            "id:id\n" +
            "name:昵称\n" +
            "bCode:编号\n" +
            "pinyin:昵称拼音\n" +
            "gender:性别\n" +
            "phone:手机\n" +
            "idCardPic:身份证图片正面\n" +
            "idCardPicB:身份证图片背面\n" +
            "height:身高\n" +
            "weight:体重\n" +
            "education:学历\n" +
            "occupation:职业\n" +
            "salary:年薪\n" +
            "house:房子\n" +
            "car:车子\n" +
            "selfSituation:自身情况\n" +
            "hobby:爱好\n" +
            "requirements:择偶要求\n" +
            "birthday:生日\n" +
            "marriage:婚姻\n" +
            "nativePlace:籍贯\n" +
            "liveCity:居住\n" +
            "nativePlaceV:籍贯值\n" +
            "liveCityV:居住值\n" +
            "wechatCode:微信\n" +
            "idCard:身份证\n" +
            "educationPic:学历照片\n" +
            "photo:个人照片\n" +
            "photoPrivacy:个人照片_隐藏\n" +
            "examined: 审核状态: 未审核,未通过,已审核\n" +
            "orderNum:排序\n" +
            "createTime:创建时间\n" +
            "createUser:创建人\n" +
            "updateTime:更新时间\n" +
            "updateUser:更新人\n" +
            "", httpMethod = "GET")
    @ApiPageParam
    @GetMapping("/list2")
    public JsonResult list2(PageResult2<T> page, Appointments appointments) throws Exception {
        return appointmentsService.list2(page, appointments, getLoginUser());
    }

    /**
     * 查询全部用户资料
     */
    @PreAuthorize("hasAuthority('appo:appointments:list')")
    //@OperLog(value = "用户资料", desc = "查询全部")
    @ApiOperation("查询全部用户资料")
    @GetMapping()
    public JsonResult list(Appointments appointments) {
        return appointmentsService.list(appointments, getLoginUser());
    }

    /**
     * 根据id查询用户资料
     */
    @PreAuthorize("hasAuthority('appo:appointments:list')")
    //@OperLog(value = "用户资料", desc = "根据id查询")
    @ApiOperation("根据id查询用户资料")
    @GetMapping("/get")
    public JsonResult get(Appointments appointments) {
        return appointmentsService.getById(appointments);
        // 使用关联查询
        //PageParam<appointments> pageParam = new PageParam<>();
        //pageParam.put("id", id);
        //List<appointments> records = appointmentsService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }

    /**
     * 根据id查询用户资料
     */
    @PreAuthorize("hasAuthority('appo:appointments:list')")
    @ApiOperation("根据id查询用户资料")
    @GetMapping("/getByAppoUserId")
    public JsonResult getByAppoUserId() {
        return appointmentsService.getByAppoUserId(getLoginUserId()+"");
    }


    /**
     * 添加用户资料
     */
    @PreAuthorize("hasAuthority('appo:appointments:save')")
    @OperLog(value = "用户资料", desc = "添加", param = false, result = true)
    @ApiOperation(value = "添加用户资料", notes = "" +
            "name:昵称\n" +
            "pinyin:昵称拼音\n" +
            "gender:性别\n" +
            "phone:手机\n" +
            "idCardPic:身份证图片正面\n" +
            "idCardPicB:身份证图片背面\n" +
            "height:身高\n" +
            "weight:体重\n" +
            "education:学历\n" +
            "occupation:职业\n" +
            "salary:年薪\n" +
            "house:房子\n" +
            "car:车子\n" +
            "selfSituation:自身情况\n" +
            "hobby:爱好\n" +
            "requirements:择偶要求\n" +
            "birthday:生日\n" +
            "marriage:婚姻\n" +
            "nativePlace:籍贯\n" +
            "liveCity:居住\n" +
            "nativePlaceV:籍贯值\n" +
            "liveCityV:居住值\n" +
            "wechatCode:微信\n" +
            "idCard:身份证\n" +
            "educationPic:学历照片\n" +
            "photo:个人照片\n" +
            "photoPrivacy:个人照片_隐藏\n" +
            "orderNum:排序\n" +
            "", httpMethod = "POST")
    @PostMapping()
    public JsonResult save(Appointments appointments) {
        return appointmentsService.save(appointments, getLoginUser());
    }

    /**
     * 修改用户资料
     */
    @PreAuthorize("hasAuthority('appo:appointments:update')")
    @OperLog(value = "导入用户资料", desc = "导入", param = false, result = true)
    @ApiOperation(value = "导入用户资料", notes = "" +
            "", httpMethod = "PUT")
    @GetMapping("imPortUser")
    public JsonResult imPortUser(Appointments appointments) {
        return appointmentsService.imPortUser(appointments, getLoginUser());
    }

    /**
     * 修改用户资料
     */
    @PreAuthorize("hasAuthority('appo:appointments:update')")
    @OperLog(value = "用户资料", desc = "修改", param = false, result = true)
    @ApiOperation(value = "修改用户资料", notes = "" +
            "id:id\n" +
            "name:昵称\n" +
            "pinyin:昵称拼音\n" +
            "gender:性别\n" +
            "phone:手机\n" +
            "idCardPic:身份证图片正面\n" +
            "idCardPicB:身份证图片背面\n" +
            "height:身高\n" +
            "weight:体重\n" +
            "education:学历\n" +
            "occupation:职业\n" +
            "salary:年薪\n" +
            "house:房子\n" +
            "car:车子\n" +
            "selfSituation:自身情况\n" +
            "hobby:爱好\n" +
            "requirements:择偶要求\n" +
            "birthday:生日\n" +
            "marriage:婚姻\n" +
            "nativePlace:籍贯\n" +
            "liveCity:居住\n" +
            "nativePlaceV:籍贯值\n" +
            "liveCityV:居住值\n" +
            "wechatCode:微信\n" +
            "idCard:身份证\n" +
            "educationPic:学历照片\n" +
            "photo:个人照片\n" +
            "photoPrivacy:个人照片_隐藏\n" +
            "orderNum:排序\n" +
            "", httpMethod = "PUT")
    @PutMapping()
    public JsonResult update(Appointments appointments) {
        return appointmentsService.update(appointments, getLoginUser());
    }

    /**
     * 修改用户资料
     */
    @PreAuthorize("hasAuthority('appo:appointments:update')")
    @OperLog(value = "用户资料", desc = "修改", param = false, result = true)
    @ApiOperation(value = "修改用户资料", notes = "" +
            "id:id\n" +
            "examined: 审核状态: 未审核,未通过,已审核\n" +
            "", httpMethod = "PUT")
    @PostMapping("updateExamined")
    public JsonResult updateExamined(Appointments appointments, Message message) {
        return appointmentsService.updateExamined(appointments, message, getLoginUser());
    }

    /**
     * 删除用户资料
     */
    @PreAuthorize("hasAuthority('appo:appointments:remove')")
    @OperLog(value = "用户资料", desc = "删除", result = true)
    @ApiOperation("删除用户资料")
    @DeleteMapping("/remove")
    public JsonResult remove(Appointments appointments) {
        return appointmentsService.remove(appointments, getLoginUser());
    }

    /**
     * 批量添加用户资料
     */
    /**@RequiresPermissions("appo:appointments:save")
     @OperLog(value = "用户资料", desc = "批量添加", param = false, result = true)
     @ResponseBody
     @PostMapping("/saveBatch") public JsonResult saveBatch(@RequestBody List<Appointments> list) {
     if (appointmentsService.saveBatch(list)) {
     return JsonResult.ok("添加成功");
     }
     return JsonResult.error("添加失败");
     }*/

    /**
     * 批量修改用户资料
     */
    /**@RequiresPermissions("appo:appointments:update")
     @OperLog(value = "用户资料", desc = "批量修改", result = true)
     @ResponseBody
     @PutMapping("/updateBatch") public JsonResult updateBatch(@RequestBody BatchParam<Appointments> batchParam) {
     if (batchParam.update(appointmentsService, "")) {
     return JsonResult.ok("修改成功");
     }
     return JsonResult.error("修改失败");
     }*/

    /**
     * 批量删除用户资料
     */
    /**@RequiresPermissions("appo:appointments:remove")
     @OperLog(value = "用户资料", desc = "批量删除", result = true)
     @ResponseBody
     @DeleteMapping("/removeBatch") public JsonResult removeBatch(@RequestBody List<Integer> ids) {
     if (appointmentsService.removeByIds(ids)) {
     return JsonResult.ok("删除成功");
     }
     return JsonResult.error("删除失败");
     }*/

}
